<?php
/**
 * Created by PhpStorm.
 * User: xiaxiang
 * Date: 2019/3/24
 * Time: 14:06
 */


//注册于登录控制器
class LoginAction extends Action
{
    public function index()
    {
        $this->display();
    }

    //注册
    public function register()
    {
        $this->display();
    }

    //注册表单处理
    public function runRegis(){
        p($_POST);
    }

    //获取验证码
    public function verify()
    {
        //载入验证码的类
        import('ORG.Util.Image');
        Image::buildImageVerify(4, 1, 'png');
    }

    //异步验证账号是否存在
    public function checkAccount()
    {
//        p($_POST);
        if (!$this->isAjax()) {
            halt('页面不存在');
        }
        $account = $this->_post('account');
        $where = array('account' => $account);
        if (M('user')->where($where)->getField('id')) {
            echo 'false';
        } else {
            echo 'true';
        }
    }

    //异步验证昵称是否已经存在
    public function checkUname()
    {
        if (!$this->isAjax()) {
            halt('页面不存在');
        }
        $uname = $this->_post('uname');
        $where = array('username' => $uname);
        if (M('userinfo')->where($where)->getField('id')) {
            echo 'false';
        } else {
            echo 'true';
        }
    }

    //验证验证码
    public function checkVerify()
    {
        if (!$this->isAjax()) {
            halt('页面不存在');
        }
        $verify = $this->_post('verify');
        if ($_SESSION['verify'] != md5($verify)) {
            echo 'false';
        } else {
            echo 'true';
        }

    }
}